using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing ;
using System.Text;
using System.Windows.Forms;

namespace PrintPreviewControlProject
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            PrintDocument document = new PrintDocument();            
            printPreviewControl1.Name = "PrintPreviewControl1";           
            document.PrintPage += new PrintPageEventHandler(document_PrintPage);
            printPreviewControl1.Document = document;       
            printPreviewControl1.Document.DocumentName = "PrintPreviewControl1";
           
        }
        private void document_PrintPage(object sender, PrintPageEventArgs e)
        {
            string text = "Welcome to C# 2005";
            Font printFont =
                new Font("Arial", 35,
                FontStyle.Regular);

            e.Graphics.DrawString(text, printFont,
                Brushes.Black, 0, 0);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form frm = new Form();

            PrintPreviewControl ppc = new PrintPreviewControl();
            ppc.Location = new Point(88, 80);
            ppc.Name = "PrintPreviewControl1";
            ppc.Dock = DockStyle.Fill;

            PrintDocument document = new PrintDocument();

            ppc.Document = document;
            document.PrintPage += new PrintPageEventHandler(document_PrintPage);
            ppc.Document.DocumentName = "PrintPreviewControl1";
            frm.Controls.Add(ppc);
            frm.ShowDialog();
        }
    }
}